package com.rtthreadlocal.threadlocalstarter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * <p>ThreadLocalAutoConfiguration .
 *
 * <p>change history:
 *
 * <pre>
 * date         defect       person          comments
 * --------------------------------------------------------------------------------
 * 2025/6/2    ********     Tao Ren    create file.
 * </pre>
 *
 * @author Tao Ren
 * @date 2025/6/2 20:43
 */

@Configuration
@ConditionalOnClass(ThreadLocal.class)
@EnableConfigurationProperties(ThreadLocalProperties.class)
public class ThreadLocalAutoConfiguration {
    @Autowired
    private ThreadLocalProperties properties;

    @Bean
    @ConditionalOnMissingBean
    public ThreadLocalUtil threadLocalUtil() {
        ThreadLocalUtil.setPrefix(properties.getPrefix());
        return new ThreadLocalUtil();
    }
}
